<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>天天生鲜-登陆</title>
<link rel="icon" href="images/copylogo.png">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/login.css">
</head>

<body>
	<!-- logo区区域 -->
	<div class="login_top">
    	<a href="index.html" class="login_logo"><img src="images/logo02.png"></a>
    </div>
	
	<!-- 内容区域 -->
    <div class="login_form_bg">
    	<div class="login_form_wrap clearfix">
        	<div class="login_banner fl"></div>
            <div class="slogn fl">日夜兼程 · 急速送达</div>	
            <div class="login_form fr">
                <div class="login_title	clearfix">
                    <h1 class="fl">用户登陆</h1>
                    <a href="register.html" class="fl">立即注册</a>
                </div>
				<!-- 登录区域 -->
                <div class="form_input clearfix">
                    <form>
						<ul>
                            <li>
                                <input type="text" name="nickname" class="name_input" id="nickname" placeholder="请输入用户名" id="nickname">
                                <div class="user_error">输入错误</div>
                            </li>
                            <li>
                                <input type="password" name="pwd" class="pwd_input" id="pwd" placeholder="请输入密码" id="pwd">
                                <div class="pwd_error">密码错误</div>
                            </li>
                            <li>
                            	<div>
                                <input type="text" name="yzm" id="yzm" class="yzm_input"
                                placeholder="请输入验证码">
                                <img class="code" id="image" src="images/yzm1.png" />
                                </div>
                                <input type="button"  value="看不清,换一张"  onclick="refresh()"	/>
                                <div class="code_error">验证码错误</div>
                            </li>
                            <li>
                                <div class="more_input clearfix">
                                    <input type="checkbox" name="" id="remember">
                                    <label for="remember">记住用户名</label>
                                    <a href="#">忘记密码</a>
                                </div>
                            </li>
                            <li>
                               <input type="button" value="登录" class="submit_input" onclick = "login()">
                            </li>
                      	</ul>
                    </form>
                </div>
            </div>
         </div>
    </div>
	
	<!-- 版权所有-->
    <div class="footer">
    	<div class="foot_link">
        	<a href="#">关于我们</a><span> | </span>
        	<a href="#">联系我们</a><span> | </span>
        	<a href="#">招聘广告</a><span> | </span>
            <a href="#">友情链接</a>
        </div>
        <p>CopyRight &copy;  2019 嘟嘟嘟水果欢迎你的到来 All Rights Reserverd</p>
        <p>电话： </p>
    </div>
	<script src="js/jquery-3.4.1.min.js"></script>
	<script>
		ryzm='5809';
		console.log(ryzm);

		//切换验证码
		function refresh(){
			var src="images/yzm"+(Math.floor(Math.random() * 4)+1)+".png";			
			$("#image").attr('src', src);
			var str = src.substr(10, 1);
			switch(str){
				case '1' :ryzm='5809'; break;
				case '2' :ryzm='5739'; break;
				case '3' :ryzm='vwo7'; break;
				case '4' :ryzm='7364'; break;
			}
		}
		
		//模拟登陆
		function login(	){
			//获取用户名
			var nickname = $("#nickname").val();
			//获取密码
			var pwd = $("#pwd").val();
			//获取验证码
			var yzm = $("#yzm").val();
			//判断
			if(nickname =='' && pwd ==''){
				alert("用户名或密码不能为空..");
				return;
			}
			//判断验证码是否正确
			if(yzm != ryzm){
				alert("验证码错误");
				return;
			}
			console.log("登录");
			//登陆
			$.post("menberInfo/login", {nickname:nickname, pwd:pwd},function(data){
				if(data <= 0){//登录失败
					alert("登录失败,用户名或密码错误,请重新再试...");
					window.location.href = "login.html";
				} else {
					//跳转转网页
					alert("登录成功,即将跳转到主页...");
					window.location.href = "index.html";	
				}
			});
		}
	</script>
</body>
</html>
